package cn.itsource.hrm.fallback;

import cn.itsource.hrm.feignclients.RedisFeignClient;
import cn.itsource.hrm.util.AjaxResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RedisFeignClientFallbackFactory implements FallbackFactory<RedisFeignClient> {

    @Override
    public RedisFeignClient create(Throwable throwable) {
        return new RedisFeignClient() {
            /*
            * 这两个方法就是拖底方法,拖底方法返回false，就会从数据库查数据
            * */
            @Override
            public AjaxResult set(String key, String value) {
                //throwable.printStackTrace();
                System.out.println("我是托底set方法");
                return AjaxResult.me().setSuccess(false).setMessage("redis服务不可用: "+throwable.getMessage());
            }

            @Override
            public AjaxResult setex(String key, int seconds, String value) {
                System.out.println("我是托底setex方法");
                return AjaxResult.me().setSuccess(false).setMessage("redis服务不可用: "+throwable.getMessage());
            }

            @Override
            public AjaxResult get(String key) {
                //throwable.printStackTrace();
                System.out.println("我是托底get方法");
                return AjaxResult.me().setSuccess(false).setMessage("redis服务不可用: "+throwable.getMessage());
            }
        };
    }
}
